{* *}
{php}
	global $db, $dblang, $globals, $main_smarty, $search, $offset, $from_where, $page_size, $link_id;
{/php}

{* display top stories header *}
<h2>{#PLIGG_Visual_TopStories_Header#}</h2>

{php}
{* order stories in descending order by number of votes *}
$order_by = " ORDER BY votes DESC ";

echo '<div id="contents"><center>';

{* display the "all 24 hours this week this month this year" links *} 
do_sidebar_top();

echo '</center>';

{* select the stories from the database and count the number of rows *}
$link = new Link;
$rows = $db->get_var("SELECT count(*) FROM " . table_links . " WHERE $time_link link_status != 'discard'");
$links = $db->get_results("SELECT link_id, count(*) as votes $from_where $order_by LIMIT $offset,$page_size");

{* display stories *}
if ($links) {
	foreach($links as $dblink) {
		$link->id=$dblink->link_id;
		$link->read();
		$link->print_summary('summary');
	}
}

echo '</div>';

{* display "previous" and "next" page links *}
do_pages($rows, $page_size, $the_page);

{/php}
